import { User, UserProfile } from '@/types/data'
import { RootAction } from '@/types/store'

type StateType = {
  user: User
  userProfile: UserProfile
}

const initValue = {
  // 基本资料
  user: {} as User,
  // 详细资料
  userProfile: {} as UserProfile,
}

export default function profileReducer(
  state: StateType = initValue,
  action: RootAction
) {
  if (action.type === 'profile/set_user') {
    return {
      ...state,
      user: action.payload,
    }
  }

  if (action.type === 'profile/set_user_profile') {
    return {
      ...state,
      userProfile: action.payload,
    }
  }

  return state
}
